iT邦幫忙

DAY 34
3

鐵之 Just Do Lotus Notes系列 第 34

代理程式範本 - 處理選擇文件

  • 分享至 

  • xImage
  •  

代理程式範本 - 處理選擇文件($Agent Template - Process Selected)
今天要介紹的是老少咸宜的東西,把這存起來對之後新舊手來說都是一個好的片段程式碼,做這項功能時就不用再去哪找一些範例還改了,直接用就上手.


常常會用到的就是要處理多份文件,
這一個代理程式範本就可以直接拿來套用來改,還可以計算執行百分比..

Option Public
Option Declare
'Use "OpenLogFunctions"
Sub Initialize
	On Error Goto Errorhandler
	Dim ws As New NotesUIWorkspace
	Dim session As New NotesSession
	Dim db As NotesDatabase
	Dim dc As NotesDocumentCollection
	Dim doc As NotesDocument
	Dim total As Long
	Dim docnum As Long
	
	'Get a handle on the selected documents
	Set db = session.CurrentDatabase
	
	'Optional OpenLog command to force logging to the current database - remove to use default (which may also be current db)
	'Call UseCustomLogDb (db) 	
	
	Set dc = db.UnprocessedDocuments
	total = dc.Count
	docnum = 0
	
	Set doc = dc.GetFirstDocument
	While Not doc Is Nothing
		docnum = docnum + 1
		Call UpdateStatusBar(docnum, total) 
		
		Call ProcessDocSample(doc)
		'<<<<<<<<< Insert your code here >>>>>>>>>>>
		
		doc.Form = "Test"
		
		'Call doc.ComputeWithForm(False, False)			'unrem if you want all form fields to recompute
		Call doc.Save(True, False)
		Set doc = dc.GetNextDocument(doc)
	Wend
	
	Call ws.ViewRefresh
	
	
	Exit Sub
	
Errorhandler:
	'See the "Using This Database" for details on error handling with OpenNTF OpenLog
	'Call LogError
	Exit Sub
	
End Sub
Sub ProcessDocSample(doc As NotesDocument)
	On Error Goto stackError
	
	'<<<<<<<< Do stuff to the document >>>>>>>>>
	
	Exit Sub
	
stackError:
	'This will report any errors here up to the calling sub/function (e.g. "Initialize")
	'Call AddToStackTrace()
End Sub
Sub UpdateStatusBar(x As Long, total As Long)
	'This will display the percentage complete in the status bar as the agent runs
	
	Print "Working..." & Cstr(Round((x / total), 2)*100) & "% done"
	
End Sub

上一篇
Lotus Domino安裝Dojo的環境方式比較
下一篇
在本機修改ID相關資訊(密碼強度及認證到期日...)
系列文
鐵之 Just Do Lotus Notes41
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
ted99tw
iT邦高手 1 級 ‧ 2012-10-27 23:34:42

好久沒看人用VB了...

讚讚讚

其實這是 Lotus Script,但是語法都是類似VB.

我要留言

立即登入留言